from urllib.request import Request, urlopen
from fake_useragent import UserAgent
from urllib.parse import urlencode
from urllib.request import HTTPCookieProcessor,build_opener

# 实现在代码中登录并爬取登陆后的网页内容
# 登录
login_url = "https://mail.qq.com/"
headers = {
    "User-Agent": UserAgent().chrome
}
form_data = {
    "sid": "EiV94MoinWPcKh1D",
    "stat": "log_ad_show",
    "loc": "qqmail_HY_Width",
    "err": "timeout"
}
f_data = urlencode(form_data).encode()
request = Request(login_url, headers=headers)
#response = urlopen(request)
handler=HTTPCookieProcessor()
opener=build_opener(handler)
response=opener.open(request)
print(response.read().decode("utf-8","ignore"))
# 访问页面：
info_url = "https://ssl.captcha.qq.com/cap_union_new_verify"
response = Request(info_url, headers=headers)
# response = urlopen(request)
response=opener.open(request)
print(response.read().decode("utf-8","ignore"))
